package com.ruoyi.omp.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.omp.api.RemoteRoomService;
import com.ruoyi.omp.api.domain.BuiRoom;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.math.BigDecimal;
import java.util.List;

/**
 * 房屋信息降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteRoomFactory implements FallbackFactory<RemoteRoomService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteRoomFactory.class);

    @Override
    public RemoteRoomService create(Throwable throwable) {
        log.error("房屋信息服务调用失败:{}", throwable.getMessage());
        return new RemoteRoomService() {
            /**
             * 通过租赁记录id查询房屋列表
             *
             * @param buiRoom 房屋信息
             * @return
             */
            @Override
            public R<List<BuiRoom>> listRoom(BuiRoom buiRoom) {
                return R.fail("获取房屋信息失败:" + throwable.getMessage());
            }

            @Override
            public R<BuiRoom> getBuiRoomByNum(String roomNum) {
                return R.fail("获取房屋信息失败:" + throwable.getMessage());
            }

            /**
             * 查询房屋详情
             *
             * @param roomId 房屋id
             * @return
             */
            @Override
            public R<BuiRoom> getBuiRoom(String roomId) {
                return R.fail("获取房屋信息失败:" + throwable.getMessage());
            }

            @Override
            public R updateRoom(@RequestBody BuiRoom buiRoom) {
                return R.fail("修改房屋信息失败:" + throwable.getMessage());
            }

            /**
             * 通过租赁记录id查询租赁总面积
             *
             * @param recordId 租赁记录id
             * @return
             */
            @Override
            public R<BigDecimal> sumRoomAreaByRecordId(String recordId) {
                return R.fail("查询租赁总面积失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> countRoomByRecordId(String recordId) {
                return R.fail("查询房屋数量失败:" + throwable.getMessage());
            }
        };
    }
}
